package com.ruitu.mall_98_2.mine;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.androidkun.xtablayout.XTabLayout;
import com.beanu.arad.base.my_base.MyBaseActivity;
import com.beanu.arad.widget.progressactivity.ProgressLayout;
import com.ruitu.mall_98_2.R;
import com.ruitu.mall_98_2.mine.fragment.BalanceFragment;
import com.ruitu.mall_98_2.mine.fragment.IntegralFragment;

public class WalletActivity extends MyBaseActivity {
    private XTabLayout tab;
    private ViewPager vp;

    private VpAdapter adapter;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_wallet;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        tab = findViewById(R.id.tab);
        vp = findViewById(R.id.vp);

        adapter = new VpAdapter(getSupportFragmentManager());
        vp.setAdapter(adapter);
        tab.setupWithViewPager(vp);

        setHeadTitle("我的钱包");
    }

    private class VpAdapter extends FragmentPagerAdapter {

        public VpAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return BalanceFragment.newInstance();
            } else {
                return IntegralFragment.newInstance();
            }
        }

        @Override
        public CharSequence getPageTitle(int position) {
            if (position == 0) {
                return "余额";
            } else {
                return "积分";
            }
        }

        @Override
        public int getCount() {
            return 2;
        }
    }

    @Override
    protected ProgressLayout findProgressLayout() {
        return null;
    }
}
